﻿<?php

	////source datetime convert functions////
	function xl2ts($xl_date){return($xl_date - 25569) * 86400 - 18000 ;}//-3600
	function ts2xl($ts_date){return($ts_date + 25569 * 86400 + 18000 )/86400;}//+3600
	
//function xl2ts(&$xl_date){return(($xl_date - 25569)*86400 - 21600);}
//function ts2xl(&$ts_date){return($ts_date + 2209183200)/86400;}

//function dt_converter(&$xl_dt  ){return $xl_dt   = date('Y-m-d H:i:s', xl2ts($xl_dt));}
function dt_converter(&$xl_dt  ){
	list($date, $time) = explode('.',$xl_dt);
	$time = '0.'.(string)$time;
	$time = (float)$time;
//echo $date.' '.$time.'<br/>';
	return $xl_dt = date('Y-m-d', xl2ts($date)).' '.date('H:i:s',round($time * 86400-18000 ,0));
}
function d_converter (&$xl_date){return $xl_date = date('Y-m-d'      , xl2ts($xl_date));}
function t_converter (&$xl_time){return $xl_time = date('H:i:s'      , round($xl_time * 86400-18000 ,0));}
function dt_parse    (&$dt){
	$dtarr = explode(' ', $dt);
	list($year_, $month_, $day_) = explode('-',$dtarr[0]);
	list($hours_,$minutes_,$seconds_) = explode(':',$dtarr[1]);
	return $dt = ts2xl(mktime($hours_,$minutes_,$seconds_,$month_,$day_,$year_));
}
function dt_parse2   ($dt){
	$dtarr = explode(' ', $dt);
	list($year_, $month_, $day_) = explode('-',$dtarr[0]);
	list($hours_,$minutes_,$seconds_) = explode(':',$dtarr[1]);
	$secs = $seconds_ + $minutes_*60 + ($hours_)*3600;
	$dt2 = array();
	$dt2['date'] = ts2xl(mktime(0,0,0,$month_,$day_,$year_));
	//$dt2['time'] = ts2xl(mktime($hours_,$minutes_,$seconds_,1,1,1900));
	$dt2['time'] = $secs/86400;
	//echo $secs.'<br/>';
	return $dt2;
}
?>